1、按之字形打印二叉树

/*
struct TreeNode {
    int val;
    struct TreeNode *left;
    struct TreeNode *right;
    TreeNode(int x) :
            val(x), left(NULL), right(NULL) {
    }
};
*/
class Solution {
public:
    vector<vector<int> > Print(TreeNode* pRoot) {
        vector<vector<int>> vv;
        if(pRoot==nullptr)
            return vv;
        vector<int> v;
        queue<TreeNode*> q;
        q.push(pRoot);
        int a=1;
        while(!q.empty())
        {
            a=-a;
            int n=q.size();
            while(n--)
            {
                TreeNode* top=q.front();
                q.pop();
                v.push_back(top->val);
                if(top->left)
                    q.push(top->left);
                if(top->right)
                    q.push(top->right);
            }
            if(a==1)
            {
                reverse(v.begin(),v.end());
            }
            vv.push_back(v);
            v.clear();
        }
        return vv;;
    }
    
};